package com.ruoyi.web.enums;

import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.web.service.StrategyService;
import com.ruoyi.web.service.impl.strategy.ImageTextStrategyImpl;
import com.ruoyi.web.service.impl.strategy.VoteStrategyImpl;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * 策略模式-发表文章枚举
 */
@Getter
@AllArgsConstructor
public enum ArticleTypeEnum {

    IMAGE_TEXT("image_text", ImageTextStrategyImpl.class,"普通图文"),
    VOTE("vote", VoteStrategyImpl.class,"投票")
    ;

    private final String value;
    private final Class<?> strategyService;
    private final String desc;
    private static final Map<ArticleTypeEnum,Class<?>> STRATEGY_MAP = new HashMap<>();

    static {
        for(ArticleTypeEnum value : ArticleTypeEnum.values()){
            STRATEGY_MAP.put(value,value.getStrategyService());
        }
    }

    public StrategyService getEnumStrategyService(){
        return (StrategyService) SpringUtils.getBean(STRATEGY_MAP.get(this));
    }

}
